import json

import requests


# 发起事件工单
class __event_monitor__:
    def __create_new__(self):
        # URL 地址
        url = 'http://10.10.80.200:7948/api/inf/eventmonitor/newEvent'

        with open('/gs/data/request/事件/派单入参.json', 'r',
                  encoding='utf-8') as file:
            json_data: str = file.read()
        data = json.loads(json_data)

        # 发送 POST 请求
        response = requests.post(url, json=data)

        # 打印响应的内容
        if response.status_code == 200:
            response_data = json.loads(response.text)
            # 格式化JSON输出
            formatted_response_data = json.dumps(response_data, indent=4, ensure_ascii=False)
            # 将响应结果写入新文件
            with open('/gs/data/response/事件/response.json', 'w',
                      encoding='utf-8') as outfile:
                outfile.write(formatted_response_data)
            print("响应已成功写入文件：/Users/rongjiping/AquaProjects/TestPython/甘肃/data/response/事件/response.json")
        else:
            print(f"请求失败，状态码：{response.status_code}")

    def __pre_treatment__(self):
        # URL 地址
        url = 'http://10.10.80.200:7948/api/inf/eventmonitor/pretreatmentPosiDelimit'
        # url = 'http://localhost:7944/api/eventmonitor/process/pretreatmentPosiDelimit'

        data = {
            "alarmId": "93135750202281741038",
            "sheetNo": "GS-906-241028-00002",
            "complaint": "投诉1",
            "effectResult": "网络层面：1）承载电路信息：电路名称:中国甘肃陇南礼县城关传输-中国甘肃陇南礼县祁山GE0002NR,业务类型:5G基站（5G）;\r\n电路名称:中国甘肃陇南武都东江生产楼-中国甘肃陇南礼县祁山FE0001KA/P,业务类型:KA(大客户专线);\r\n2）承载业务系统明细：业务层面：集客：；家客：；无线：基站退服总数：0，2G基站退服数：0，4G基站退服数：0，5G基站退服数：0;社会层面：该事件无相关投诉信息 ， 无社会舆情、无网络安全影响。",
            "effectType": "业务影响类型2",
            "hiddenDesc": "隐患详情2",
            "posResult": "定界定位结论2",
            "preStep": "事件预处理步骤2",
            "rootProfessional": "传输网",
            "faultRootType": "工程操作"
        }
        # "faultroottype": "工程操作"
        #         }

        # 发送 POST 请求
        response = requests.post(url, json=data)

        # 打印响应的内容
        if response.status_code == 200:
            response_data = json.loads(response.text)
            # 格式化JSON输出
            formatted_response_data = json.dumps(response_data, indent=4, ensure_ascii=False)
            # 将响应结果写入新文件
            with open('response.json', 'w', encoding='utf-8') as outfile:
                outfile.write(formatted_response_data)
            print("响应已成功写入文件：response.json")
        else:
            print("请求失败，状态码：{response.status_code}")
